package com.lxy_s_springboot.lxy_s_springboot.controller;


import com.lxy_s_springboot.lxy_s_springboot.model.User;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RequestMapping("/param")
@RestController
public class ParamController {
    @RequestMapping("/p1")
    public String p1(String name,Integer age){
        return "name:"+name+",age:"+age;
    }
    @RequestMapping("/p2")
    public String p2(Integer age){
        return "age:"+age;
    }
    @RequestMapping("/p3")
    public String p3(int age){
        return "age:"+age;
    }
    @RequestMapping("/p5")
    public String p5(Long age){
        return "age:"+age;
    }
    @RequestMapping("/p6")
    public String p6(long age){
        return "age:"+age;
    }
    @RequestMapping("/p4")
    public String p4(boolean is){
        return "is:"+is;
    }
    @RequestMapping("/p7")
    public String p7(User user){
        return "user:"+user;
    }
    //给参数重命名
    @RequestMapping("/p8")
    public String p8(@RequestParam(value = "userName",required = false) String name){
        return "name:"+name;
    }
    @RequestMapping("/p9")
    public String p9(String[] name){
        return "name[]:"+ List.of(name);
    }

    @RequestMapping("/p10")
    public String p10(@RequestParam List<String> name){
        return "namelist:"+ name;
    }
    @RequestMapping("/p11")
    public String p11(@RequestBody User user){
        return "user:"+ user;
    }
    @RequestMapping("/article/{articleId}")
    public String p12(@PathVariable String articleId){
        return "articleId"+articleId;
    }
    @RequestMapping("/article1/{id}/{name}")
    public String p13(@PathVariable("id") String articleId,@PathVariable String name){
        return "articleId"+articleId+name;
    }
    @RequestMapping("/p13")
    public String p13(@RequestPart("name") MultipartFile file){
        System.out.println(file.getOriginalFilename());
        return "file:"+file.getOriginalFilename();
    }
}
